package org.casper.outofmemory;

import java.util.HashMap;
import java.util.Map;

public class TestMemoryLeak {

	static class ID {
		Integer id;

		public ID(Integer id) {
			this.id = id;
		}

		@Override
		public int hashCode() {
			return id.hashCode();
		}

		@Override
		public boolean equals(Object o) {
			boolean response = false;
			if (o instanceof ID) {
				response = (((ID) o).id).equals(this.id);
			}
			return response;
		}
	}

	public static void main(String[] args) {
		Map<ID, String> map = new HashMap<>();
		while (true) {
			for (int i = 0; i < 10000; i++) {
				if (!map.containsKey(new ID(i))) {
					try {
						map.put(new ID(i), "Number: " + i);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}

	}
}
